package com.lam.fundamental;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class ListViewActivity extends Activity{

	private ListView listView;
	private EditText editText;
	private ArrayList<String> data;
	private ArrayAdapter<String> adapter;
	private Button button;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview);
		listView=(ListView)findViewById(R.id.lv_show);
		editText=(EditText)findViewById(R.id.et_listview_add);
		button=(Button)findViewById(R.id.bt_listview_add);
		data=new ArrayList<String>();
		adapter=new ArrayAdapter<String>(this,R.layout.todolist_item,data);
		listView.setAdapter(adapter);
		
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String content=editText.getText().toString();
				data.add(content);
				adapter.notifyDataSetChanged();
				editText.setText("");
			}
		});
		
	}
	
}
